package com.alphawavesgames.engine.rendering;

import android.content.Context;

/**
 *
 * @author Duncan
 */
public class GLRenderContainer extends RenderContainer
{
    private Context m_context;
    
    protected GLRenderContainer( Context context )
    {
        m_context = context;
        //m_renderInterface = new GLRenderHWInterface();
        //need to create a GLRenderHWInterface that extends from GLRenderHWInterface
        m_renderInterface = new GLRenderHWInterface();

        m_textureManager = new GLTextureManager();
        //construct platform specific engine classes
        m_spriteRenderer = new GLSpriteRenderer();
        //m_textureManager = new TextureManagerAndroid( context.getResources() );
        m_fontRenderer = new FontRendererAndroid();
        //m_shapeRenderer = new ShapeRendererAndroid();
    }

    //get the singleton
    public static GLRenderContainer getRenderContainer()
    {
        return ( GLRenderContainer ) s_renderContainer;
    }

    //create the singleton
    public static GLRenderContainer createRenderContainer( Context context )
    {
        if( s_renderContainer == null )
        {
            s_renderContainer = new GLRenderContainer( context );
        }
        return ( GLRenderContainer ) s_renderContainer;
    }

    //GL specific -

    @Override
    public void initialise()
    {
        m_renderInterface.initialise( this );
        ( (GLSpriteRenderer)m_spriteRenderer ).initialise( this );
        ( (GLTextureManager)m_textureManager ).initialise( this );
    }

    @Override
    public void finalise()
    {
        super.finalise();
    }

    //this should be called when the render HW interface has been created
    //need this callback because we dont create the render device
    @Override
    public void onRenderHWInterfaceCreated()
    {
        if( m_onInitCallback != null )
        {
            //call the callback
            m_onInitCallback.onEngineInitialised();
        }
    }

    @Override
    public GLRenderHWInterface getRenderHWInterface() { return (GLRenderHWInterface)m_renderInterface; }
    //accessors to platform specific versions
    //public TextureManagerAndroid getTextureManagerAndroid() { return ( TextureManagerAndroid ) m_textureManager; }
    public GLTextureManager getTextureManagerGL() { return ( GLTextureManager )m_textureManager; }
    //public GLSpriteRenderer getSpriteRendererAndroid() { return ( GLSpriteRenderer ) m_spriteRenderer; }

    public Context getContext() { return m_context; }
}
